package cn.ywsj.ywsjmidtier.controller;

import cn.ywsj.ywsjmidtier.entity.VO.ShoppingCartQueryVo;
import cn.ywsj.ywsjmidtier.entity.VO.ShoppingCartVo;
import cn.ywsj.ywsjmidtier.entity.VO.ThOrderListVo;
import cn.ywsj.ywsjmidtier.service.WechatShoppingCartFeign;
import cn.ywsj.ywsjmidtier.utils.JsonObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.Feature;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@Api(tags = "购物车")
@RestController
@RequestMapping("/wechat/member/shoppingcatmgr")
public class WechatShoppingCartController {

    @Autowired
    private WechatShoppingCartFeign cartFeign;

    /**
     * 购物车_提交订单
     * @param orderListVo
     * @param session
     * @param obj
     * @return
     */
    @ApiOperation("购物车_提交订单")
    @PostMapping("/ajaxordersubmit")
    public String addOrderSubmit(ThOrderListVo orderListVo, HttpSession session) {
        return cartFeign.addOrderSubmit(JsonObjectUtil.ObjectToJson(orderListVo),session);
    }

    /**
     * 购物车_下单
     * @param shoppingCartQueryVo
     * @param session
     * @return
     */
    @ApiOperation("购物车_下单")
    @PostMapping("/ajaxneworderconfirm")
    public String ajaxNewOrderconfirm(ShoppingCartQueryVo shoppingCartQueryVo,HttpSession session) {
        return cartFeign.ajaxNewOrderconfirm(JsonObjectUtil.ObjectToJson(shoppingCartQueryVo),session);
    }

    /**
     * 购物车_加入购物车
     * @param cartList
     * @return
     */
    @ApiOperation("购物车_加入购物车")
    @PostMapping("/ajaxaddshoppingcart")
    public String addShoppingCart(String cartList) {
        return cartFeign.addShoppingCart(cartList);
    }

    /**
     * 购物车_删除商品
     * @param session
     * @param tradeIds
     * @return
     */
    @ApiOperation("购物车_删除商品")
    @PostMapping("/delete")
    public String delete(HttpSession session, String tradeIds) {
        return cartFeign.delete(session,tradeIds);
    }

    /**
     * 购物车_选择促销
     * @param shoppingCartVo
     * @param result
     * @return
     */
    @ApiOperation("购物车_选择促销")
    @PostMapping("/updatemarketactivity")
    public String updateMarketActivity(ShoppingCartVo shoppingCartVo, BindingResult result) {
        return cartFeign.updateMarketActivity(JsonObjectUtil.ObjectToJson(shoppingCartVo),result);
    }

    /**
     * 购物车_购物车商品更新数量
     * @param shoppingCartQueryVo
     * @param beforeDesc
     * @return
     */
    @ApiOperation("购物车_购物车商品更新数量")
    @PostMapping("/updatecartnum")
    public String updatecartnum(ShoppingCartQueryVo shoppingCartQueryVo,String beforeDesc) {
        return cartFeign.updatecartnum(JsonObjectUtil.ObjectToJson(shoppingCartQueryVo),beforeDesc);
    }

    /**
     * 购物车_购物车列表
     * @param shoppingCartQueryVo
     * @return
     */
    @ApiOperation("购物车_购物车列表")
    @PostMapping("/ajaxmains")
    public String ajaxmains(ShoppingCartQueryVo shoppingCartQueryVo) {
        JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(shoppingCartQueryVo),JSONObject.class, Feature.OrderedField);
        return cartFeign.ajaxmains(jsonObject);
    }

    /**
     * 点击再次购买
     * @param cartList
     * @return
     */
    @ApiOperation("点击再次购买")
    @PostMapping("/ajaxaddtocart")
    public String ajaxaddtocart(String cartList){
        return cartFeign.ajaxaddtocart(cartList);
    }

    @PostMapping("/queryordercount")
    public String queryOrderCount(ShoppingCartQueryVo shoppingCartQueryVo){
        JSONObject jsonObject = JsonObjectUtil.ObjectToJson(shoppingCartQueryVo);
        return cartFeign.queryOrderCount(jsonObject);
    }

    @PostMapping("/addresschange")
    public String addressList(String addressId, HttpSession session){
        return cartFeign.addressList(addressId,session);
    }
}

